import Tip from "../core/Tip"
import GameConstants from "../GameConstants"
import DataMgr from "../manager/DataMgr"
import GameMgr from "../manager/GameMgr"
import SceneMgr from "../manager/SceneMgr"

const { ccclass } = cc._decorator


@ccclass
export default class Login extends cc.Component {
    protected onLoad(): void {
        this.init()
    }


    private init() {
        SceneMgr.inst.preloadScene(GameConstants.scene.Game)

        const editAccount = this.node.getChildByName('editAccount').getComponent(cc.EditBox)

        const btnInto = this.node.getChildByName('btnInto')
        btnInto.on('click', () => {
            const account = editAccount.string.trim()
            if (!account) {
                Tip.show('请输入账号')
                return
            }

            DataMgr.inst.account = account
            GameMgr.inst.connect()
        })
    }
}
